package qldc.pm.qlktcsdldc.actions;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import qldc.pm.csdl.cd90.model.AnhChanDung;
import qldc.pm.csdl.cd90.model.CMND;
import qldc.pm.csdl.cd90.model.DanToc;
import qldc.pm.csdl.cd90.model.GioiTinh;
import qldc.pm.csdl.cd90.model.HoVaTen;
import qldc.pm.csdl.cd90.model.NgaySinh;
import qldc.pm.csdl.cd90.model.NgheNghiep;
import qldc.pm.csdl.cd90.model.NoiLamViec;
import qldc.pm.csdl.cd90.model.NoiOHienTai;
import qldc.pm.csdl.cd90.model.NoiSinh;
import qldc.pm.csdl.cd90.model.NoiThuongTru;
import qldc.pm.csdl.cd90.model.QuanHeHuyetThong;
import qldc.pm.csdl.cd90.model.QuanHeLuat;
import qldc.pm.csdl.cd90.model.QuanHeVoiChuHo;
import qldc.pm.csdl.cd90.model.QueQuan;
import qldc.pm.csdl.cd90.model.QuocTich;
import qldc.pm.csdl.cd90.model.SoHoChieu;
import qldc.pm.csdl.cd90.model.TrinhDoHocVan;
import qldc.pm.csdl.cd90.model.dto.CongDanDTO;
import qldc.pm.csdl.cd90.service.AnhChanDungLocalServiceUtil;
import qldc.pm.csdl.cd90.service.CMNDLocalServiceUtil;
import qldc.pm.csdl.cd90.service.CongDanDTOLocalServiceUtil;
import qldc.pm.csdl.cd90.service.DanTocLocalServiceUtil;
import qldc.pm.csdl.cd90.service.GioiTinhLocalServiceUtil;
import qldc.pm.csdl.cd90.service.HoVaTenLocalServiceUtil;
import qldc.pm.csdl.cd90.service.NgaySinhLocalServiceUtil;
import qldc.pm.csdl.cd90.service.NgheNghiepLocalServiceUtil;
import qldc.pm.csdl.cd90.service.NoiLamViecLocalServiceUtil;
import qldc.pm.csdl.cd90.service.NoiOHienTaiLocalServiceUtil;
import qldc.pm.csdl.cd90.service.NoiSinhLocalServiceUtil;
import qldc.pm.csdl.cd90.service.NoiThuongTruLocalServiceUtil;
import qldc.pm.csdl.cd90.service.QuanHeHuyetThongLocalServiceUtil;
import qldc.pm.csdl.cd90.service.QuanHeLuatLocalServiceUtil;
import qldc.pm.csdl.cd90.service.QuanHeVoiChuHoLocalServiceUtil;
import qldc.pm.csdl.cd90.service.QueQuanLocalServiceUtil;
import qldc.pm.csdl.cd90.service.QuocTichLocalServiceUtil;
import qldc.pm.csdl.cd90.service.SoHoChieuLocalServiceUtil;
import qldc.pm.csdl.cd90.service.TrinhDoHocVanLocalServiceUtil;
import qldc.pm.qlktcsdldc.data.UtilsData;
import qldc.pm.qlktcsdldc.dto.DanCuDTO;
import qldc.pm.qlktcsdldc.dto.LichSuDTO;
import qldc.pm.qlktcsdldc.emun.ThongTinThayDoiEnum;
import qldc.pm.qlktcsdldc.portlet.QLKTCSDLDCContants;
import qldc.pm.qlktcsdldc.report.CongDan90Report;
import qldc.pm.qlktcsdldc.report.LichSuReport;
import qldc.pm.qlktcsdldc.utils.FLog;
import qldc.pm.qlktcsdldc.utils.Utils;
import qldc.pm.qtht.dmdc.model.PhuongXa;
import qldc.pm.qtht.dmdc.model.QuanHeGiaDinh;
import qldc.pm.qtht.dmdc.model.QuanHuyen;
import qldc.pm.qtht.dmdc.model.Tinh;
import qldc.pm.qtht.dmdc.service.PhuongXaLocalServiceUtil;
import qldc.pm.qtht.dmdc.service.QuanHeGiaDinhLocalServiceUtil;
import qldc.pm.qtht.dmdc.service.QuanHuyenLocalServiceUtil;
import qldc.pm.qtht.dmdc.service.TinhLocalServiceUtil;
import qldc.pm.qtht.dmdc.utils.DiaChiUtils;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.ServletResponseUtil;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.JavaConstants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.User;
import com.liferay.portal.util.PortalUtil;
import com.report.logic.Report;



public class QuanLyDanCuAction {	
	private static final Log _Log = LogFactoryUtil.getLog(QuanLyDanCuAction.class.getName());

	public void xuatThongTinRaFile(ActionRequest actionRequest, ActionResponse actionResponse) {
		FLog.Log("xuatThongTinRaFile");
		SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
		String redirect = ParamUtil.getString(actionRequest, "redirect");

		try {
			User user = PortalUtil.getUser(actionRequest);
			if (Validator.isNotNull(user)) {
				String soDinhDanhCaNhan = ParamUtil.getString(actionRequest, "soDinhDanhCaNhan");
				FLog.Log("xuatThongTinRaFile:" + soDinhDanhCaNhan);
				CongDanDTO  congDanDTO = CongDanDTOLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
				writeXMLCongDan(actionRequest, actionResponse, congDanDTO);
			}
			else {
				SessionErrors.add(actionRequest, "vui-long-dang-nhap");
			}

			if (redirect != null && redirect.length() > 0)
				actionResponse.sendRedirect(redirect);

		}
		catch (PortalException e) {
			_Log.error(e);
		}
		catch (SystemException e) {
			_Log.error(e);
		}
		catch (IOException e) {
			_Log.error(e);
		}
	}
	public void QLDC_ManHinhChinh_ExportDanCu(ActionRequest actionRequest, ActionResponse actionResponse) {
		FLog.Log("QLDC_ManHinhChinh_ExportDanCu");
		SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
		String redirect = ParamUtil.getString(actionRequest, "redirect");
		PortletConfig portletConfig = (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

		try {
			User user = PortalUtil.getUser(actionRequest);
			if (Validator.isNotNull(user)) {
				long _tinhId = ParamUtil.getLong(actionRequest, "tinh");
				long _quanHuyenId = ParamUtil.getLong(actionRequest, "quanHuyen");
				long _phuongXaId = ParamUtil.getLong(actionRequest, "phuongXa");
				String _dCThuongTru = ParamUtil.getString(actionRequest, "dCThuongTru");
				String _soDinhDanhCaNhan = ParamUtil.getString(actionRequest, "soDinhDanhCaNhan");
				String _soCMND = ParamUtil.getString(actionRequest, "soCMND");
				List<Object[]>results = NoiThuongTruLocalServiceUtil.QLTKDL_SearchCongDan(_tinhId, _quanHuyenId, _phuongXaId, _dCThuongTru, _soDinhDanhCaNhan, _soCMND, -1, -1);
				
				String xmlFilePath = QLKTCSDLDCContants.XML_FILE_PATH + "\\" + "dancu" + ".xml";
				DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
	            DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
	            Document document = documentBuilder.newDocument();
	 
	            // root element
	            Element root = document.createElement("DanCu");
	            document.appendChild(root); 
	            
				for (Object[] search : results) {
					DanCuDTO _congDan = new DanCuDTO();
					if(((Object[])search)[0] != null)
						_congDan.setSoDinhDanhCaNhan(((Object[])search)[0].toString());
					if(((Object[])search)[1] != null)
						_congDan.setHoVaTen(((Object[])search)[1].toString());
					if(((Object[])search)[2] != null)
						_congDan.setNgaySinh(Utils.formatDateToStringSQL(((Object[])search)[2].toString()));
					if(((Object[])search)[3] != null)
						_congDan.setSoCMND(((Object[])search)[3].toString());
					if(((Object[])search)[4] != null)
						_congDan.setNgayCapCMND(Utils.formatDateToStringSQL(((Object[])search)[4].toString()));
					if(((Object[])search)[5] != null)
						_congDan.setGioiTinh(Integer.parseInt(((Object[])search)[5].toString()));
					if(((Object[])search)[6] != null)
						_congDan.setTinhId(Long.parseLong(((Object[])search)[6].toString()));
					if(((Object[])search)[7] != null)
						_congDan.setQuanHuyenId(Long.parseLong(((Object[])search)[7].toString()));
					if(((Object[])search)[8] != null)
						_congDan.setPhuongXaId(Long.parseLong(((Object[])search)[8].toString()));
					if(((Object[])search)[9] != null)
						_congDan.setDiaChi(((Object[])search)[9].toString());

					String _soSoHoKhau ="";
					QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(_congDan.getSoDinhDanhCaNhan());
					if(Validator.isNotNull(quanHeVoiChuHo)){
						_soSoHoKhau = quanHeVoiChuHo.getSoSoHoKhau();
					}
					String _gioiTinh = _congDan.getGioiTinh() == 1? LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nam"):LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nu");
					
					Element congDan = document.createElement("CongDan");
			        root.appendChild(congDan); 
			        
			        // SoDinhDanhCaNhan element
		            Element soDinhDanhCaNhan = document.createElement("SoDinhDanhCaNhan");
		            soDinhDanhCaNhan.appendChild(document.createTextNode(_congDan.getSoDinhDanhCaNhan()));
		            congDan.appendChild(soDinhDanhCaNhan);
		         
		            // HoVaTen element
		            Element hoVaTen = document.createElement("HoVaTen");
		            hoVaTen.appendChild(document.createTextNode(_congDan.getHoVaTen()));
		            congDan.appendChild(hoVaTen);
		            
		            // NgaySinh element
		            Element ngaySinh = document.createElement("NgaySinh");
		            ngaySinh.appendChild(document.createTextNode(_congDan.getNgaySinh()));
		            congDan.appendChild(ngaySinh);
		            
		            // SoCMND element
		            Element soCMND = document.createElement("SoCMND");
		            soCMND.appendChild(document.createTextNode(_congDan.getSoCMND()));
		            congDan.appendChild(soCMND);
		 
		            // NgayCapCMND element
		            Element ngayCapCMND = document.createElement("NgayCapCMND");
		            ngayCapCMND.appendChild(document.createTextNode(_congDan.getNgayCapCMND()));
		            congDan.appendChild(ngayCapCMND);
		            
		            // GioiTinh element
		            Element gioiTinh = document.createElement("GioiTinh");
		            gioiTinh.appendChild(document.createTextNode(_gioiTinh));
		            root.appendChild(gioiTinh);
		            
		            // SoSoHoKhau element
		            Element soSoHoKhau = document.createElement("SoSoHoKhau");
		            soSoHoKhau.appendChild(document.createTextNode(_soSoHoKhau));
		            congDan.appendChild(soSoHoKhau);
		            
		            // diaChiThuongTru element
		            Element diaChiThuongTru = document.createElement("DiaChiThuongTru");
		            congDan.appendChild(diaChiThuongTru);
		            
		            Element noiThuongTruTinhId = document.createElement("NoiThuongTruTinhId");
		            noiThuongTruTinhId.appendChild(document.createTextNode(_congDan.getTinhId()+""));
		            diaChiThuongTru.appendChild(noiThuongTruTinhId);
		            
		            Element noiThuongTruQuanHuyenId = document.createElement("NoiThuongTruQuanHuyenId");
		            noiThuongTruQuanHuyenId.appendChild(document.createTextNode(_congDan.getQuanHuyenId()+""));
		            diaChiThuongTru.appendChild(noiThuongTruQuanHuyenId);
		            
		            Element noiThuongTruPhuongXaId = document.createElement("NoiThuongTruPhuongXaId");
		            noiThuongTruPhuongXaId.appendChild(document.createTextNode(_congDan.getPhuongXaId()+""));
		            diaChiThuongTru.appendChild(noiThuongTruPhuongXaId);
		            
		            Element noiThuongTruDiaChi = document.createElement("NoiThuongTruDiaChi");
		            noiThuongTruDiaChi.appendChild(document.createTextNode(_congDan.getDiaChi()+""));
		            diaChiThuongTru.appendChild(noiThuongTruDiaChi);
				}
				  
	            // create the xml file
	            //transform the DOM Object to an XML File
	            TransformerFactory transformerFactory = TransformerFactory.newInstance();
	            Transformer transformer = transformerFactory.newTransformer();
	            transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
	            
	            DOMSource domSource = new DOMSource(document);
	            StreamResult streamResult = new StreamResult(new File(xmlFilePath));
	 
	            // If you use
	            // StreamResult result = new StreamResult(System.out);
	            // the output will be pushed to the standard output ...
	            // You can use that for debugging
	 
	            transformer.transform(domSource, streamResult);
	 
	            FLog.Log("****** Done creating XML File *******");
			}
			else {
				SessionErrors.add(actionRequest, "vui-long-dang-nhap");
			}

			if (redirect != null && redirect.length() > 0)
				actionResponse.sendRedirect(redirect);

		}
		catch (PortalException e) {
			_Log.error(e);
		}
		catch (SystemException e) {
			_Log.error(e);
		}
		catch (IOException e) {
			_Log.error(e);
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void QLDC_ManHinhChinh_In(ActionRequest actionRequest, ActionResponse actionResponse) {
		FLog.Log("QLDC_ManHinhChinh_In");
		SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
		String redirect = ParamUtil.getString(actionRequest, "redirect");
		PortletConfig portletConfig = (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

		try {
			User user = PortalUtil.getUser(actionRequest);
			if (Validator.isNotNull(user)) {
				long _tinhId = ParamUtil.getLong(actionRequest, "tinh");
				long _quanHuyenId = ParamUtil.getLong(actionRequest, "quanHuyen");
				long _phuongXaId = ParamUtil.getLong(actionRequest, "phuongXa");
				String _dCThuongTru = ParamUtil.getString(actionRequest, "dCThuongTru");
				String _soDinhDanhCaNhan = ParamUtil.getString(actionRequest, "soDinhDanhCaNhan");
				String _soCMND = ParamUtil.getString(actionRequest, "soCMND");
				List<Object[]>results = NoiThuongTruLocalServiceUtil.QLTKDL_SearchCongDan(_tinhId, _quanHuyenId, _phuongXaId, _dCThuongTru, _soDinhDanhCaNhan, _soCMND, -1, -1);
				
				String _tinh = "";
				if(_tinhId > 0){
					Tinh tinh = TinhLocalServiceUtil.findById(_tinhId);
					if(Validator.isNotNull(tinh)){
						_tinh = tinh.getTenTinh();
					}
				}
				String _quan = "";
				if(_quanHuyenId > 0){
					QuanHuyen quanHuyen = QuanHuyenLocalServiceUtil.findById(_quanHuyenId);
					if(Validator.isNotNull(quanHuyen)){
						_quan = quanHuyen.getTenQuanHuyen();
					}
				}
				String _phuong = "";
				if(_phuongXaId > 0){
					PhuongXa phuongXa = PhuongXaLocalServiceUtil.findById(_phuongXaId);
					if(Validator.isNotNull(phuongXa)){
						_phuong = phuongXa.getTenPhuongXa();
					}
				}
				
				List<CongDan90Report> lstCongDan = new ArrayList<CongDan90Report>();
				int start =0;
				for (Object[] search : results) {
					DanCuDTO _congDan = new DanCuDTO();
					if(((Object[])search)[0] != null)
						_congDan.setSoDinhDanhCaNhan(((Object[])search)[0].toString());
					if(((Object[])search)[1] != null)
						_congDan.setHoVaTen(((Object[])search)[1].toString());
					if(((Object[])search)[2] != null)
						_congDan.setNgaySinh(Utils.formatDateToStringSQL(((Object[])search)[2].toString()));
					if(((Object[])search)[3] != null)
						_congDan.setSoCMND(((Object[])search)[3].toString());
					if(((Object[])search)[4] != null)
						_congDan.setNgayCapCMND(Utils.formatDateToStringSQL(((Object[])search)[4].toString()));
					if(((Object[])search)[5] != null)
						_congDan.setGioiTinh(Integer.parseInt(((Object[])search)[5].toString()));
					if(((Object[])search)[6] != null)
						_congDan.setTinhId(Long.parseLong(((Object[])search)[6].toString()));
					if(((Object[])search)[7] != null)
						_congDan.setQuanHuyenId(Long.parseLong(((Object[])search)[7].toString()));
					if(((Object[])search)[8] != null)
						_congDan.setPhuongXaId(Long.parseLong(((Object[])search)[8].toString()));
					if(((Object[])search)[9] != null)
						_congDan.setDiaChi(((Object[])search)[9].toString());
					String _diaChi = DiaChiUtils.createBlockDiaChi(_congDan.getTinhId(), _congDan.getQuanHuyenId(), _congDan.getPhuongXaId(), _congDan.getDiaChi());

					String _soSoHoKhau ="";
					QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(_congDan.getSoDinhDanhCaNhan());
					if(Validator.isNotNull(quanHeVoiChuHo)){
						_soSoHoKhau = quanHeVoiChuHo.getSoSoHoKhau();
					}
					String _gioiTinh = _congDan.getGioiTinh() == 1? LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nam"):LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nu");
					CongDan90Report congDan90Report = new CongDan90Report();
					start++;
					congDan90Report.setStt(String.valueOf(start));
					congDan90Report.setSoDinhDanhCaNhan(_congDan.getSoDinhDanhCaNhan());
					congDan90Report.setHoVaTen(_congDan.getHoVaTen());
					congDan90Report.setNgaySinh(_congDan.getNgaySinh());
					congDan90Report.setSoCMND(_congDan.getSoCMND());
					congDan90Report.setNgayCap(_congDan.getNgayCapCMND());
					congDan90Report.setGioiTinh(_gioiTinh);
					congDan90Report.setSoSoHoKhau(_soSoHoKhau);
					congDan90Report.setDiaChiThuongTru(_diaChi);
					
					lstCongDan.add(congDan90Report);
				}
				// create file PDF
				HashMap<String, Object> data = new HashMap<String, Object>();
				data.put("tinh", _tinh);
				data.put("quanHuyen", _quan);
				data.put("phuongXa", _phuong);
				data.put("diaChi", _dCThuongTru);
				data.put("soDinhDanhCaNhan", _soDinhDanhCaNhan);
				data.put("soCMND", _soCMND);
				data.put("list_congdan", lstCongDan);
				PortletContext pc = actionRequest.getPortletSession().getPortletContext();
				String reportFileName = "Quan_ly_dan_cu_90";
				String reportFilePath = pc.getRealPath(QLKTCSDLDCContants.REPORT_FOLDER + "/" + reportFileName + ".jrxml");

				File file = Report.createReport(data, Report.DOC_TYPE, reportFilePath, reportFileName);
				if(Validator.isNotNull(file)) {
					InputStream in = new FileInputStream(file);

					HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest);
					HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);
					ServletResponseUtil.sendFile(httpServletRequest, httpServletResponse, reportFileName + "." + Report.DOC_TYPE, in, "application/pdf");
				}
				
				SessionMessages.add(actionRequest, "file-in-duoc-mo-vui-long-kiem-tra-file-in");  
	           
			}
			else {
				SessionErrors.add(actionRequest, "vui-long-dang-nhap");
			}

			if (redirect != null && redirect.length() > 0)
				actionResponse.sendRedirect(redirect);

		}
		catch (PortalException e) {
			_Log.error(e);
		}
		catch (SystemException e) {
			_Log.error(e);
		}
		catch (IOException e) {
			_Log.error(e);
		}
	}
	private void writeXMLCongDan(ActionRequest actionRequest, ActionResponse actionResponse, CongDanDTO congDanDTO){
//		PortletContext pc = actionRequest.getPortletSession().getPortletContext();
//		String xmlFilePath = pc.getRealPath(QLKTCSDLDCContants.XML_FILE_PATH + "/" + "congdan" + ".xml");
		String xmlFilePath = QLKTCSDLDCContants.XML_FILE_PATH + "\\" + "congdan" + ".xml;";
		PortletConfig portletConfig = (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

		try {	 
	            DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
	            DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
	            Document document = documentBuilder.newDocument();
	 
	            // root element
	            Element root = document.createElement("CongDan");
	            document.appendChild(root); 
	        
	            // SoDinhDanhCaNhan element
	            Element soDinhDanhCaNhan = document.createElement("SoDinhDanhCaNhan");
	            soDinhDanhCaNhan.appendChild(document.createTextNode(congDanDTO.getSoDinhDanhCaNhan()));
	            root.appendChild(soDinhDanhCaNhan);
	         
	            // HoVaTen element
	            Element hoVaTen = document.createElement("HoVaTen");
	            hoVaTen.appendChild(document.createTextNode(congDanDTO.getHoVaTen()));
	            root.appendChild(hoVaTen);
	            
	            // NgaySinh element
	            Element ngaySinh = document.createElement("NgaySinh");
	            ngaySinh.appendChild(document.createTextNode(congDanDTO.getNgaySinh()));
	            root.appendChild(ngaySinh);
	            
	            // SoCMND element
	            Element soCMND = document.createElement("SoCMND");
	            soCMND.appendChild(document.createTextNode(congDanDTO.getSoCMND()));
	            root.appendChild(soCMND);
	 
	            // NgayCapCMND element
	            Element ngayCapCMND = document.createElement("NgayCapCMND");
	            ngayCapCMND.appendChild(document.createTextNode(congDanDTO.getNgayCapCMND()));
	            root.appendChild(ngayCapCMND);
	            
	            // GioiTinh element
	            Element gioiTinh = document.createElement("GioiTinh");
	            String _gioiTinh = congDanDTO.getGioiTinh() == 1 ? LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nam") : 
	            										LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nu");
	            gioiTinh.appendChild(document.createTextNode(_gioiTinh));
	            root.appendChild(gioiTinh);
	            
	            // NgayCapCMND element
	            Element soSoHoKhau = document.createElement("SoSoHoKhau");
	            soSoHoKhau.appendChild(document.createTextNode(congDanDTO.getSoSoHoKhau()));
	            root.appendChild(soSoHoKhau);
	            
	            // NgayCapCMND element
	            Element diaChiThuongTru = document.createElement("DiaChiThuongTru");
	            root.appendChild(diaChiThuongTru);
	            
	            Element noiThuongTruTinhId = document.createElement("NoiThuongTruTinhId");
	            noiThuongTruTinhId.appendChild(document.createTextNode(congDanDTO.getNoiThuongTruTinhId()+""));
	            diaChiThuongTru.appendChild(noiThuongTruTinhId);
	            
	            Element noiThuongTruQuanHuyenId = document.createElement("NoiThuongTruQuanHuyenId");
	            noiThuongTruQuanHuyenId.appendChild(document.createTextNode(congDanDTO.getNoiThuongTruQuanHuyenId()+""));
	            diaChiThuongTru.appendChild(noiThuongTruQuanHuyenId);
	            
	            Element noiThuongTruPhuongXaId = document.createElement("NoiThuongTruPhuongXaId");
	            noiThuongTruPhuongXaId.appendChild(document.createTextNode(congDanDTO.getNoiThuongTruPhuongXaId()+""));
	            diaChiThuongTru.appendChild(noiThuongTruPhuongXaId);
	            
	            Element noiThuongTruDiaChi = document.createElement("NoiThuongTruDiaChi");
	            noiThuongTruDiaChi.appendChild(document.createTextNode(congDanDTO.getNoiThuongTruDiaChi()+""));
	            diaChiThuongTru.appendChild(noiThuongTruDiaChi);
	           
	            // create the xml file
	            //transform the DOM Object to an XML File
	            TransformerFactory transformerFactory = TransformerFactory.newInstance();
	            Transformer transformer = transformerFactory.newTransformer();
	            transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
	            
	            DOMSource domSource = new DOMSource(document);
	            StreamResult streamResult = new StreamResult(new File(xmlFilePath));
	 
	            // If you use
	            // StreamResult result = new StreamResult(System.out);
	            // the output will be pushed to the standard output ...
	            // You can use that for debugging
	 
	            transformer.transform(domSource, streamResult);
	 
	            FLog.Log("****** Done creating XML File *******");
 
	        } catch (ParserConfigurationException pce) {
	            pce.printStackTrace();
	        } catch (TransformerException tfe) {
	            tfe.printStackTrace();
	        }
			    
	}
	
	public void thongTinCongDanIn(ActionRequest actionRequest, ActionResponse actionResponse) {
		FLog.Log("thongTinCongDanIn");
		SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
		String redirect = ParamUtil.getString(actionRequest, "redirect");
		PortletConfig portletConfig = (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

		try {
			User user = PortalUtil.getUser(actionRequest);
			if (Validator.isNotNull(user)) {
				String soDinhDanhCaNhan = ParamUtil.getString(actionRequest, "soDinhDanhCaNhan");
				
				CongDanDTO congDanDTO = null;
				String _tonGiao="";
				String _danToc ="";
				String _noiSinh = "";
				String _noiThuongTru ="";
				String _noiOHienTai = "";
				String _ngaySinh = "";
				if(Validator.isNotNull(soDinhDanhCaNhan)){
					congDanDTO = CongDanDTOLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
					if(Validator.isNotNull(congDanDTO)){
						System.out.println("Thong tin chung :"+ congDanDTO.toString());
						qldc.pm.csdl.cd90.model.TonGiao tonGiao = qldc.pm.csdl.cd90.service.TonGiaoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
						if(Validator.isNotNull(tonGiao)){
							qldc.pm.qtht.dmdc.model.TonGiao tonGiaoDMCD = qldc.pm.qtht.dmdc.service.TonGiaoLocalServiceUtil.findById(tonGiao.getDmdcTonGiaoId());
							if(Validator.isNotNull(tonGiaoDMCD)){
								_tonGiao = tonGiaoDMCD.getTenTonGiao();
							}
						}
						
						qldc.pm.csdl.cd90.model.DanToc danToc = qldc.pm.csdl.cd90.service.DanTocLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
						if(Validator.isNotNull(danToc)){
							qldc.pm.qtht.dmdc.model.DanToc danTocDMDC = qldc.pm.qtht.dmdc.service.DanTocLocalServiceUtil.findById(danToc.getDmdcDanTocId());
							if(Validator.isNotNull(danTocDMDC)){
								_danToc = danTocDMDC.getTenDanToc();
							}
						}
						
						_noiSinh = DiaChiUtils.createBlockDiaChi(congDanDTO.getNoiSinhTinhId(), congDanDTO.getNoiSinhQuanHuyenId(), congDanDTO.getNoiSinhPhuongXaId(), congDanDTO.getNoiSinhDiaChi());
						_noiThuongTru = DiaChiUtils.createBlockDiaChi(congDanDTO.getNoiThuongTruTinhId(), congDanDTO.getNoiThuongTruQuanHuyenId(), congDanDTO.getNoiThuongTruPhuongXaId(), congDanDTO.getNoiThuongTruDiaChi());
						_noiOHienTai = DiaChiUtils.createBlockDiaChi(congDanDTO.getNoiOHienTaiTinhId(), congDanDTO.getNoiOHienTaiQuanHuyenId(), congDanDTO.getNoiOHienTaiPhuongXaId(), congDanDTO.getNoiOHienTaiDiaChi());
						
						if(Validator.isNotNull(congDanDTO.getNgaySinh())){
							System.out.println("Thong tin chung :"+ congDanDTO.getNgaySinh());
							_ngaySinh = congDanDTO.getNgaySinh();
						}
					}
				}
				
				// create file PDF
				HashMap<String, Object> data = new HashMap<String, Object>();
				//Thong tin chung
				data.put("hoVaTen", Validator.isNotNull(congDanDTO) ? congDanDTO.getHoVaTen() :"");
				data.put("hoVaTenKhac", "");
				data.put("gioiTinh",Validator.isNotNull(congDanDTO) && congDanDTO.getGioiTinh()== 1 ? LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nam"): LanguageUtil.get(portletConfig, actionRequest.getLocale(), "nu"));
				data.put("quocTich", Validator.isNotNull(congDanDTO) ? congDanDTO.getQuocTich():"" );
				data.put("tonGiao", _tonGiao);
				data.put("danToc", _danToc);
				data.put("ngaySinh", _ngaySinh);
				data.put("noiSinh", _noiSinh);
				data.put("soCMND", Validator.isNotNull(congDanDTO) ? congDanDTO.getSoCMND() :"");
				data.put("soHoChieu", Validator.isNotNull(congDanDTO) ? congDanDTO.getSoHoChieu():"");
				data.put("theBaoHiemYT", Validator.isNotNull(congDanDTO) ? congDanDTO.getSoTheBaoHiemYTe():"");
				data.put("maSoThueCaNhan", Validator.isNotNull(congDanDTO) ? congDanDTO.getMaSoThueCaNhan() :"");
				data.put("noiThuongTru", _noiThuongTru);
				data.put("noiOHienTai", _noiOHienTai);
				
				//Thong tin ho khau
				String _hoTenChuHo  = "";
				String _quanHeVoiChuHo = "";
				String _soSoHoKhau ="";
				if(Validator.isNotNull(soDinhDanhCaNhan)){
					_hoTenChuHo = congDanDTO.getHoVaTenChuHo();
					QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
					if(Validator.isNotNull(quanHeVoiChuHo)){
						_soSoHoKhau = quanHeVoiChuHo.getSoSoHoKhau();
						QuanHeGiaDinh quanHeGiaDinh = QuanHeGiaDinhLocalServiceUtil.findById(quanHeVoiChuHo.getDmdcQuanHeGiaDinhId());
						if(Validator.isNotNull(quanHeGiaDinh)){
							_quanHeVoiChuHo = quanHeGiaDinh.getTenQuanHeGiaDinh();
						}
					}
					_noiThuongTru = DiaChiUtils.createBlockDiaChi(congDanDTO.getNoiThuongTruTinhId(), congDanDTO.getNoiThuongTruQuanHuyenId(), congDanDTO.getNoiThuongTruPhuongXaId(), congDanDTO.getNoiThuongTruDiaChi());
					_noiOHienTai = DiaChiUtils.createBlockDiaChi(congDanDTO.getNoiOHienTaiTinhId(), congDanDTO.getNoiOHienTaiQuanHuyenId(), congDanDTO.getNoiOHienTaiPhuongXaId(), congDanDTO.getNoiOHienTaiDiaChi());
				}
				data.put("soSoHoKhau", _soSoHoKhau);
				data.put("haVaTenChuHo", _hoTenChuHo);
				data.put("quanHeVoiChuHo", _quanHeVoiChuHo);
				data.put("diaChiChuHo", _noiThuongTru);
				data.put("noiOChuHo", _noiOHienTai);
				
				//hoc van va nghe nghiep
				String _trinhDoHoVan  = "";
				String _truongTotNghiep = "";
				String _trinhDoChuyenMon ="";
				String _noiTotNghiep = "";
				String _ngheNghiep ="";
				String _noiLamViec ="";
				if(Validator.isNotNull(soDinhDanhCaNhan)){
					if(Validator.isNotNull(congDanDTO)){
						TrinhDoHocVan trinhDoHocVan = TrinhDoHocVanLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
						if(Validator.isNotNull(trinhDoHocVan)){
							 qldc.pm.qtht.dmdc.model.TrinhDoHocVan trinhDoHocVanDMDC = qldc.pm.qtht.dmdc.service.TrinhDoHocVanLocalServiceUtil.fetchTrinhDoHocVan(trinhDoHocVan.getDmdcTrinhDoHocVanId());
							if(Validator.isNotNull(trinhDoHocVanDMDC)){
								_trinhDoHoVan = trinhDoHocVanDMDC.getTenTrinhDoHocVan();
							}
							_truongTotNghiep = trinhDoHocVan.getTruongTotNghiep();
							_noiTotNghiep = trinhDoHocVan.getDiaChi();
						}
						
						_trinhDoChuyenMon = congDanDTO.getTrinhDoChuyenMon();
						_ngheNghiep = congDanDTO.getNgheNghiep();
						_noiLamViec = DiaChiUtils.createBlockDiaChi(congDanDTO.getNoiLamViecTinhId(), congDanDTO.getNoiLamViecQuanhHuyenId(), congDanDTO.getNoiLamViecPhuongXaId(), congDanDTO.getNoiLamViecDiaChi());

					}
				}
				data.put("trinhDoHocVan", _trinhDoHoVan);
				data.put("truongTotNghiep", _truongTotNghiep);
				data.put("trinhDoChuyenMon", _trinhDoChuyenMon);
				data.put("noiTotNghiep", _noiTotNghiep);
				data.put("ngheNghiep", _ngheNghiep);
				data.put("noiLamViec", _noiLamViec);
				
				PortletContext pc = actionRequest.getPortletSession().getPortletContext();
				String reportFileName = "Thong_tin_cong_dan";
				String reportFilePath = pc.getRealPath(QLKTCSDLDCContants.REPORT_FOLDER + "/" + reportFileName + ".jrxml");

				File file = Report.createReport(data, Report.DOC_TYPE, reportFilePath, reportFileName);
				if(Validator.isNotNull(file)) {
					InputStream in = new FileInputStream(file);

					HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest);
					HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);
					ServletResponseUtil.sendFile(httpServletRequest, httpServletResponse, reportFileName + "." + Report.DOC_TYPE, in,  Report.DOC_STREAM_TYPE);
				}
				
				SessionMessages.add(actionRequest, "file-in-duoc-mo-vui-long-kiem-tra-file-in");

				FLog.Log("thongTinCongDanIn  cap-nhat-thanh-cong:");
			}
			else {
				SessionErrors.add(actionRequest, "vui-long-dang-nhap");
			}

			if (redirect != null && redirect.length() > 0)
				actionResponse.sendRedirect(redirect);

		}
		catch (PortalException e) {
			_Log.error(e);
		}
		catch (SystemException e) {
			_Log.error(e);
		}
		catch (IOException e) {
			_Log.error(e);
		}
	}
	
	public void LichSuThayDoi_XuatVanBan(ActionRequest actionRequest, ActionResponse actionResponse) {
		FLog.Log("LichSuThayDoi_XuatVanBan");
		SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
		String redirect = ParamUtil.getString(actionRequest, "redirect");
		PortletConfig portletConfig = (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

		try {
			User user = PortalUtil.getUser(actionRequest);
			if (Validator.isNotNull(user)) {
				long thongTinThayDoiId = ParamUtil.getLong(actionRequest, "thongTinThayDoi");
				String soDinhDanhCaNhan = ParamUtil.getString(actionRequest, "soDinhDanhCaNhan");
				ThongTinThayDoiEnum thongTinThayDoiEnum = null;
				if(thongTinThayDoiId > 0){
					thongTinThayDoiEnum = ThongTinThayDoiEnum.getByValue(thongTinThayDoiId);
				}
				List<LichSuDTO> lichSuDTOs = null;
				if(Validator.isNotNull(thongTinThayDoiEnum)){
					System.out.println("thongTinThayDoi ThongTinThayDoiEnum"+ thongTinThayDoiEnum.getKey() +" >" + thongTinThayDoiEnum.getKey());
					lichSuDTOs = UtilsData.getLichSu(soDinhDanhCaNhan, thongTinThayDoiId, actionRequest.getLocale(), portletConfig);
				}
				String _truongThayDoi = LanguageUtil.get(portletConfig, actionRequest.getLocale(), thongTinThayDoiEnum.getKey());
				List<LichSuReport> lichSuReports = new ArrayList<LichSuReport>();
				for(int i=0; i < lichSuDTOs.size(); i++){
					LichSuReport lichSuReport = new LichSuReport();
					lichSuReport.setStt((i+1)+"");
					lichSuReport.setTruongThayDoi(_truongThayDoi);
					lichSuReport.setNgayThayDoi(lichSuDTOs.get(i).getNgayThayDoi());
					lichSuReport.setGiaTriCu(lichSuDTOs.get(i).getGiaTriCu());
					lichSuReport.setGiaTriMoi(lichSuDTOs.get(i).getGiaTriMoi());
					lichSuReport.setChuThich(lichSuDTOs.get(i).getChuThich());
					
					lichSuReports.add(lichSuReport);
				}
			
				// create file PDF
				HashMap<String, Object> data = new HashMap<String, Object>();
				data.put("truongThongTinThayDoi", _truongThayDoi);
				data.put("soDinhDanhCaNhan", soDinhDanhCaNhan);
				data.put("list_congdan", lichSuReports);
				
				PortletContext pc = actionRequest.getPortletSession().getPortletContext();
				String reportFileName = "Lich_su_thay_doi";
				String reportFilePath = pc.getRealPath(QLKTCSDLDCContants.REPORT_FOLDER + "/" + reportFileName + ".jrxml");

				File file = Report.createReport(data, Report.DOC_TYPE, reportFilePath, reportFileName);
				if(Validator.isNotNull(file)) {
					InputStream in = new FileInputStream(file);

					HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest);
					HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);
					ServletResponseUtil.sendFile(httpServletRequest, httpServletResponse, reportFileName + "." + Report.DOC_TYPE, in, Report.DOC_STREAM_TYPE);
				}
				
				SessionMessages.add(actionRequest, "file-in-duoc-mo-vui-long-kiem-tra-file-in");

				FLog.Log("thongTinCongDanIn  cap-nhat-thanh-cong:");
			}
			else {
				SessionErrors.add(actionRequest, "vui-long-dang-nhap");
			}

			if (redirect != null && redirect.length() > 0)
				actionResponse.sendRedirect(redirect);

		}
		catch (PortalException e) {
			_Log.error(e);
		}
		catch (SystemException e) {
			_Log.error(e);
		}
		catch (IOException e) {
			_Log.error(e);
		}
	}
	 
	public void suaThongTinSave(ActionRequest actionRequest, ActionResponse actionResponse) {
		FLog.Log("suaThongTinSave");
		SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
		String redirect = ParamUtil.getString(actionRequest, "redirect");
		try {
			User user = PortalUtil.getUser(actionRequest);
			if (Validator.isNotNull(user)) {
				long thongTinThayDoiId = ParamUtil.getLong(actionRequest, "suaThongTinThayDoi");
				String soDinhDanhCaNhan = ParamUtil.getString(actionRequest, "soDinhDanhCaNhan");
				FLog.Log("suaThongTinSave thongTinThayDoiId:"+ thongTinThayDoiId);
				FLog.Log("suaThongTinSave soDinhDanhCaNhan:"+ soDinhDanhCaNhan);
				if(thongTinThayDoiId > 0){
					Date _currentDate = new Date();
					String _giaiThich = null;
					long _userId = user.getUserId();
					if(thongTinThayDoiId == ThongTinThayDoiEnum.QUEQUAN.getValue()  ||
							thongTinThayDoiId == ThongTinThayDoiEnum.THUONGTRU.getValue()  ||
							thongTinThayDoiId == ThongTinThayDoiEnum.NOIOHIENTAI.getValue()  ||
							thongTinThayDoiId == ThongTinThayDoiEnum.NOILAMVIEC.getValue()  ||
							thongTinThayDoiId == ThongTinThayDoiEnum.ODAUDEN.getValue() ||
							thongTinThayDoiId == ThongTinThayDoiEnum.CHUYENDIDAU.getValue()){
							long _tinhId = ParamUtil.getLong(actionRequest, "tinh");
							long _quanHuyenId = ParamUtil.getLong(actionRequest, "quanHuyen");
							long _phuongXaId = ParamUtil.getLong(actionRequest, "phuongXa");
							String _dCThuongTru = ParamUtil.getString(actionRequest, "diaChi");
							if(thongTinThayDoiId == ThongTinThayDoiEnum.QUEQUAN.getValue()){
								NoiSinh noiSinh = NoiSinhLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(noiSinh)){
									_giaiThich = noiSinh.getGiaiThich();
									NoiSinhLocalServiceUtil.addNoiSinh(_tinhId, _quanHuyenId, _phuongXaId, _dCThuongTru, soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.QUEQUAN.getValue()){
								QueQuan queQuan = QueQuanLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(queQuan)){
									_giaiThich = queQuan.getGiaiThich();
									QueQuanLocalServiceUtil.addQueQuan(_tinhId, _quanHuyenId, _phuongXaId, _dCThuongTru, soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.THUONGTRU.getValue()){
								NoiThuongTru noiThuongTru = NoiThuongTruLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(noiThuongTru)){
									_giaiThich = noiThuongTru.getGiaiThich();
									NoiThuongTruLocalServiceUtil.addNoiThuongTru(_tinhId, _quanHuyenId, _phuongXaId, _dCThuongTru, soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.NOIOHIENTAI.getValue()){
								NoiOHienTai noiOHienTai = NoiOHienTaiLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(noiOHienTai)){
									_giaiThich = noiOHienTai.getGiaiThich();
									NoiOHienTaiLocalServiceUtil.addNoiOHienTai(_tinhId, _quanHuyenId, _phuongXaId, _dCThuongTru, soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.NOILAMVIEC.getValue()){
								NoiLamViec noiLamViec = NoiLamViecLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								long _chucVuId = 0;
								if(Validator.isNotNull(noiLamViec)){
									_giaiThich = noiLamViec.getGiaiThich();
									_chucVuId = noiLamViec.getChucVuId();
									NoiLamViecLocalServiceUtil.addNoiLamViec(_tinhId, _quanHuyenId, _phuongXaId, _dCThuongTru, _chucVuId, soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.ODAUDEN.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), _dCThuongTru, _tinhId, _quanHuyenId, _phuongXaId, 
											quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDi(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.CHUYENDIDAU.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											quanHeVoiChuHo.getLyDoChuyenDen(), _dCThuongTru, _tinhId, _quanHuyenId, _phuongXaId,quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDi(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}

							}
						}else if(thongTinThayDoiId == ThongTinThayDoiEnum.NTNSINH.getValue()  ||
							thongTinThayDoiId == ThongTinThayDoiEnum.NGAYDEN.getValue()  ||
							thongTinThayDoiId == ThongTinThayDoiEnum.NGAYCHUYEN.getValue()){
							Date date = Utils.convertStringToDate(ParamUtil.getString(actionRequest, "typeDateValue"));
							if(thongTinThayDoiId == ThongTinThayDoiEnum.NTNSINH.getValue()){
								NgaySinh ngaySinh = NgaySinhLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(ngaySinh)){
									NgaySinhLocalServiceUtil.addNgaySinh(date, soDinhDanhCaNhan, _userId, _currentDate, ngaySinh.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.NGAYDEN.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), date, quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDi(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.NGAYCHUYEN.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), date,quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							} 
						}else if(thongTinThayDoiId == ThongTinThayDoiEnum.GIOITINH.getValue()){
							int _gioiTinh = ParamUtil.getInteger(actionRequest, "gioiTinh");
							GioiTinh gioiTinh = GioiTinhLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
							if(Validator.isNotNull(gioiTinh)){
								GioiTinhLocalServiceUtil.addGioiTinh(_gioiTinh, soDinhDanhCaNhan, _userId, _currentDate, gioiTinh.getGiaiThich());
							}
						}else if(thongTinThayDoiId == ThongTinThayDoiEnum.TONGIAO.getValue()){
							long _tonGiao = ParamUtil.getLong(actionRequest, "tonGiao");
							qldc.pm.csdl.cd90.model.TonGiao tonGiao = qldc.pm.csdl.cd90.service.TonGiaoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
							if(Validator.isNotNull(tonGiao)){
								qldc.pm.csdl.cd90.service.TonGiaoLocalServiceUtil.addTonGiao(_tonGiao, soDinhDanhCaNhan, _userId, _currentDate, tonGiao.getGiaiThich());
							}
						}else if(thongTinThayDoiId == ThongTinThayDoiEnum.DANTOC.getValue()){
							long _danToc = ParamUtil.getLong(actionRequest, "danToc");
							DanToc danToc = DanTocLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
							if(Validator.isNotNull(danToc)){
								DanTocLocalServiceUtil.addDanToc(_danToc, soDinhDanhCaNhan, _userId, _currentDate, danToc.getGiaiThich());
							}
						}else if(thongTinThayDoiId == ThongTinThayDoiEnum.QUANHECHUHO.getValue()){
							long _quanHeVoiChuHoId = ParamUtil.getLong(actionRequest, "quanHeVoiChuHo");
							QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
							if(Validator.isNotNull(quanHeVoiChuHo)){
								_giaiThich = quanHeVoiChuHo.getGiaiThich();
								QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),_quanHeVoiChuHoId,
										quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
										quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
										quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDen(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
							}
						}else{
							
							String typeInputValue = ParamUtil.getString(actionRequest, "typeInputValue");
							if(thongTinThayDoiId == ThongTinThayDoiEnum.ANHCHANDUNG.getValue()){
								AnhChanDung anhChanDung = AnhChanDungLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(anhChanDung)){
									AnhChanDungLocalServiceUtil.addAnhChanDung(soDinhDanhCaNhan, anhChanDung.getAnhChanDung(), _userId, _currentDate);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.HOVATEN.getValue()){
								HoVaTen hoVaTen = HoVaTenLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								FLog.Log("hoVaTen :"+ hoVaTen.getHoVaTen());
								if(Validator.isNotNull(hoVaTen)){
									FLog.Log("Cap nhat ho va ten");
									HoVaTen hoVaTenNew = HoVaTenLocalServiceUtil.addHoVaTen(typeInputValue, soDinhDanhCaNhan, _userId, _currentDate, hoVaTen.getGiaiThich());
									FLog.Log("Cap nhat ho va ten:"+ hoVaTenNew.getHoVaTen());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.QUOCTICH.getValue()){
								QuocTich quocTich = QuocTichLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quocTich)){
									QuocTichLocalServiceUtil.addQuocTich(typeInputValue, soDinhDanhCaNhan, _userId, _currentDate, quocTich.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.CMND.getValue()){
								CMND  cmnd = CMNDLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(cmnd)){
									CMNDLocalServiceUtil.addCMND(typeInputValue, cmnd.getNgayCapCMND(), cmnd.getNoiCapCMND(), soDinhDanhCaNhan, _userId, _currentDate, cmnd.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.HOCHIEU.getValue()){
								SoHoChieu soHoChieu = SoHoChieuLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(soHoChieu)){
									SoHoChieuLocalServiceUtil.addSoHoChieu(typeInputValue, soDinhDanhCaNhan, _userId, _currentDate, soHoChieu.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.HOTENCHA.getValue()){
								QuanHeHuyetThong quanHeHuyetThong = QuanHeHuyetThongLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeHuyetThong)){
									QuanHeHuyetThongLocalServiceUtil.addQuanHeHuyetThong(typeInputValue, quanHeHuyetThong.getSoDDCNCha(), quanHeHuyetThong.getQuocTichCha(), 
										 quanHeHuyetThong.getHoVaTenMe(), quanHeHuyetThong.getSoDDCNMe(),quanHeHuyetThong.getQuocTichMe(), soDinhDanhCaNhan, _userId, _currentDate, quanHeHuyetThong.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.SDDCHA.getValue()){
								QuanHeHuyetThong quanHeHuyetThong = QuanHeHuyetThongLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeHuyetThong)){
									QuanHeHuyetThongLocalServiceUtil.addQuanHeHuyetThong(quanHeHuyetThong.getHoVaTenCha(), typeInputValue, quanHeHuyetThong.getQuocTichCha(), 
										 quanHeHuyetThong.getHoVaTenMe(), quanHeHuyetThong.getSoDDCNMe(),quanHeHuyetThong.getQuocTichMe(), soDinhDanhCaNhan, _userId, _currentDate, quanHeHuyetThong.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.QUOCTICHCHA.getValue()){
								QuanHeHuyetThong quanHeHuyetThong = QuanHeHuyetThongLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeHuyetThong)){
									QuanHeHuyetThongLocalServiceUtil.addQuanHeHuyetThong(quanHeHuyetThong.getHoVaTenCha(), quanHeHuyetThong.getSoDDCNCha(), typeInputValue, 
										 quanHeHuyetThong.getHoVaTenMe(), quanHeHuyetThong.getSoDDCNMe(),quanHeHuyetThong.getQuocTichMe(), soDinhDanhCaNhan, _userId, _currentDate, quanHeHuyetThong.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.HOTENME.getValue()){
								QuanHeHuyetThong quanHeHuyetThong = QuanHeHuyetThongLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeHuyetThong)){
									QuanHeHuyetThongLocalServiceUtil.addQuanHeHuyetThong(quanHeHuyetThong.getHoVaTenCha(), quanHeHuyetThong.getSoDDCNCha(), quanHeHuyetThong.getQuocTichCha(), 
										 typeInputValue, quanHeHuyetThong.getSoDDCNMe(),quanHeHuyetThong.getQuocTichMe(), soDinhDanhCaNhan, _userId, _currentDate, quanHeHuyetThong.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.SDDME.getValue()){
								QuanHeHuyetThong quanHeHuyetThong = QuanHeHuyetThongLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeHuyetThong)){
									QuanHeHuyetThongLocalServiceUtil.addQuanHeHuyetThong(quanHeHuyetThong.getHoVaTenCha(), quanHeHuyetThong.getSoDDCNCha(), quanHeHuyetThong.getQuocTichCha(), 
										 quanHeHuyetThong.getHoVaTenMe(), typeInputValue,quanHeHuyetThong.getQuocTichMe(), soDinhDanhCaNhan, _userId, _currentDate, quanHeHuyetThong.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.QUOCTICHME.getValue()){
								QuanHeHuyetThong quanHeHuyetThong = QuanHeHuyetThongLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeHuyetThong)){
									QuanHeHuyetThongLocalServiceUtil.addQuanHeHuyetThong(quanHeHuyetThong.getHoVaTenCha(), quanHeHuyetThong.getSoDDCNCha(), quanHeHuyetThong.getQuocTichCha(), 
										 quanHeHuyetThong.getHoVaTenMe(), quanHeHuyetThong.getSoDDCNMe(),typeInputValue, soDinhDanhCaNhan, _userId, _currentDate, quanHeHuyetThong.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.HOTENVOCHONG.getValue()){
								QuanHeLuat quanHeLuat = QuanHeLuatLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeLuat)){
									QuanHeLuatLocalServiceUtil.addQuanHeLuat(typeInputValue, quanHeLuat.getSoDDCNNguoiQuanHe(), quanHeLuat.getQuocTichNguoiQuanHe() , quanHeLuat.getDmdcQuanHeGiaDinhId(), soDinhDanhCaNhan, _userId, _currentDate, quanHeLuat.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.SDDVOCHONG.getValue()){
								QuanHeLuat quanHeLuat = QuanHeLuatLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeLuat)){
									QuanHeLuatLocalServiceUtil.addQuanHeLuat(quanHeLuat.getHoVaTenNguoiQuanHe(), typeInputValue, quanHeLuat.getQuocTichNguoiQuanHe() , quanHeLuat.getDmdcQuanHeGiaDinhId(), soDinhDanhCaNhan, _userId, _currentDate, quanHeLuat.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.QUOCTICHVOCHONG.getValue()){
								QuanHeLuat quanHeLuat = QuanHeLuatLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeLuat)){
									QuanHeLuatLocalServiceUtil.addQuanHeLuat(quanHeLuat.getHoVaTenNguoiQuanHe(), quanHeLuat.getSoDDCNNguoiQuanHe(), typeInputValue , quanHeLuat.getDmdcQuanHeGiaDinhId(), soDinhDanhCaNhan, _userId, _currentDate, quanHeLuat.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.HOTENCHUHO.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), typeInputValue,quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDen(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.SOSOHOKHAU.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											typeInputValue, quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDen(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.SOHSHK.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),typeInputValue, quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDen(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.NGHENGHIEP.getValue()){
								NgheNghiep ngheNghiep = NgheNghiepLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(ngheNghiep)){
									NgheNghiepLocalServiceUtil.addNgheNghiep(typeInputValue, soDinhDanhCaNhan, _userId, _currentDate, ngheNghiep.getGiaiThich());
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.LYDODEN.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											typeInputValue, quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(),quanHeVoiChuHo.getLyDoChuyenDi(), quanHeVoiChuHo.getNgayChuyenDen(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}else if(thongTinThayDoiId == ThongTinThayDoiEnum.LYDOCHUYEN.getValue()){
								QuanHeVoiChuHo quanHeVoiChuHo = QuanHeVoiChuHoLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
								if(Validator.isNotNull(quanHeVoiChuHo)){
									_giaiThich = quanHeVoiChuHo.getGiaiThich();
									QuanHeVoiChuHoLocalServiceUtil.addQuanHeVoiChuHo(quanHeVoiChuHo.getSoDinhDanhCaNhanChuHo(), quanHeVoiChuHo.getHoVaTenChuHo(),quanHeVoiChuHo.getDmdcQuanHeGiaDinhId(),
											quanHeVoiChuHo.getSoSoHoKhau(), quanHeVoiChuHo.getLoaiHo(),quanHeVoiChuHo.getSoHSHK(), quanHeVoiChuHo.getNgayChuyenDen(), quanHeVoiChuHo.getODauDen(), quanHeVoiChuHo.getODauDenTinhId(), quanHeVoiChuHo.getODauDenQuanHuyenId(), quanHeVoiChuHo.getODauDenPhuongXaId(), 
											quanHeVoiChuHo.getLyDoChuyenDen(), quanHeVoiChuHo.getChuyenDiDau(), quanHeVoiChuHo.getChuyenDiDauTinhId(), quanHeVoiChuHo.getChuyenDiDauQuanHuyenId(),
											quanHeVoiChuHo.getChuyenDiDauDenPhuongXaId(), typeInputValue, quanHeVoiChuHo.getNgayChuyenDen(),quanHeVoiChuHo.getGhiChu(), soDinhDanhCaNhan, _userId, _currentDate, _giaiThich);
								}
							}  
						}
					SessionMessages.add(actionRequest, "cap-nhat-thanh-cong");
					FLog.Log("suaThongTinSave  cap-nhat-thanh-cong:");
				}else{
					SessionMessages.add(actionRequest, "cap-nhat-thanh-cong");
					FLog.Log("suaThongTinSave  cap-nhat-thanh-cong:");
				}
			}else {
				SessionErrors.add(actionRequest, "vui-long-dang-nhap");
			}

			if (redirect != null && redirect.length() > 0)
				actionResponse.sendRedirect(redirect);

		}
		catch (PortalException e) {
			_Log.error(e);
		}
		catch (SystemException e) {
			_Log.error(e);
		}
		catch (IOException e) {
			_Log.error(e);
		}
	}
	public void QLDC_ManHinhChinhAction(ActionRequest actionRequest, ActionResponse actionResponse) {
		String cmd = ParamUtil.getString(actionRequest, "cmd");	
		FLog.Log("QLDC_ManHinhChinhAction cmd >>>>>>>>>>>>>>"+cmd);
		if (cmd.equals(QLKTCSDLDCContants.IN)){
			QLDC_ManHinhChinh_In(actionRequest, actionResponse);
		} else if(cmd.equals(QLKTCSDLDCContants.EXPORT_FILE)){
			QLDC_ManHinhChinh_ExportDanCu(actionRequest, actionResponse);
		}
	}
	
	public void QLDC_KiemTraDuLieuAction(ActionRequest actionRequest, ActionResponse actionResponse) {
		String cmd = ParamUtil.getString(actionRequest, "cmd");	
		FLog.Log("QLDC_KiemTraDuLieuAction cmd >>>>>>>>>>>>>>"+cmd);
		if (cmd.equals(QLKTCSDLDCContants.IN)){
			LichSuThayDoi_XuatVanBan(actionRequest, actionResponse);
		} else if(cmd.equals(QLKTCSDLDCContants.THOAT)){
			String redirect = ParamUtil.getString(actionRequest, "redirect");
			if (redirect != null && redirect.length() > 0)
				try {
					actionResponse.sendRedirect(redirect);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}
	
	public void QLDC_LichSuThayDoiAction(ActionRequest actionRequest, ActionResponse actionResponse) {
		String cmd = ParamUtil.getString(actionRequest, "cmd");	
		FLog.Log("QLDC_LichSuThayDoiAction cmd >>>>>>>>>>>>>>"+cmd);
		if (cmd.equals(QLKTCSDLDCContants.IN)){
			LichSuThayDoi_XuatVanBan(actionRequest, actionResponse);
		} else if(cmd.equals(QLKTCSDLDCContants.THOAT)){
			String redirect = ParamUtil.getString(actionRequest, "redirect");
			if (redirect != null && redirect.length() > 0)
				try {
					actionResponse.sendRedirect(redirect);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
	}
}
